<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/20
 * Time: 14:57
 */
include '../classes/logincheck.php';
include '../classes/conn.php';
$id=$_POST['id'];
if(islogin()!='teacher_login') {
    die("error");
}
$query1="select * from sharedfile where Id='{$id}'";
$res=mysql_query($query1);
$row=mysql_fetch_assoc($res);

//移动文件
$dir1=substr($row['path'],8);
$dir1="..".$dir1;
$dir2="../Files/".$_SESSION['t_num']."/private/".$row['name'];
if(file_exists($dir2)){
    die('file_exist');
}
rename(iconv('UTF-8','gbk',$dir1),iconv('UTF-8','gbk',$dir2));


//删除数据
$query2="delete from sharedfile where Id='{$id}'";
mysql_query($query2);


//插入private的path
$dir3=substr($dir2,3);
$dir3="requests/".$dir3;
//插入数据
$query3="insert into privatefile (name, path) VALUES ('{$row['name']}','{$dir3}')";
mysql_query($query3);
echo '1';
